<template>
  <div class="main">
    <!-- 条件查询 -->
    <el-card class="card" shadow="never">
      <div slot="header" class="clearfix">
        <span class="condtion">条件查询</span>
      </div>
      <!-- 条件查询内容 -->
      <div>
        <el-form
          size="mini"
          :inline="true"
          :model="searchFrom"
          class="demo-form-inline"
        >
          <el-form-item label="订单编号" class="users">
            <el-input
              v-model="searchFrom.orderSn"
              placeholder="订单编号"
            ></el-input>
          </el-form-item>
          <el-form-item label="退单状态状态" class="users">
            <el-select
              size="mini"
              v-model="searchFrom.status"
              placeholder="请选择"
            >
              <el-option
                v-for="item in optionsers"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item class="usered">
            <el-button @click="reset">重置</el-button>
            <el-button type="primary" @click="doSearch">查询</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
    <!-- 文章列表table表单 -->
    <el-card shadow="never" class="card">
      <el-table
        border
        :data="tableData"
        style="width: 100%"
        max-height="1000"
        v-loading="loading"
      >
        <el-table-column label="#" fixed type="index" width="50">
        </el-table-column>
        <el-table-column
          prop="orderSn"
          label="订单编号"
          width="300"
          heigth="133"
          align="center"
        >
        </el-table-column>
        <el-table-column label="退单状态" width="150">
          <template slot-scope="scope">
            <div v-if="scope.row.status == 0" class="pending">待处理</div>
            <div v-if="scope.row.status == 1" class="returns">退货中</div>
            <div v-if="scope.row.status == 2" class="completed">已完成</div>
            <div v-if="scope.row.status == 3" class="refuse">已拒绝</div>
          </template>
        </el-table-column>

        <el-table-column
          prop="description"
          label="描述"
          width="150"
          align="center"
        >
        </el-table-column>

        <el-table-column
          prop="reason"
          label="退单原因"
          width="150"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="productName"
          label="商品名称"
          width="150"
          align="center"
        >
        </el-table-column>
        <el-table-column label="商品属性" width="150" align="center">
          <template slot-scope="scope">
            <div v-for="(item, index) in scope.row.productAttr" :key="index">
              {{ item.key }}:{{ item.value }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="商家备注" width="160" align="center">
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="添加时间"
          width="200"
          align="center"
        >
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="120">
          <template slot-scope="scope">
            <el-button
              @click="resetes(scope.row.id)"
              type="primary"
              align="center"
              >产看订单</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <!-- 分页 -->
    <el-pagination
      :current-page="page.currentPage"
      :page-sizes="page.pageSizes"
      :page-size="page.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="page.total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    >
    </el-pagination>
  </div>
</template>

<script>
import orderFor from '@/api/orderFor.js'
import mixin from '@/mixins'

export default {
  mixins: [mixin],
  data() {
    return {
      searchFrom: {}, //输入框里的对象
      form: {}, //实际搜索要用的表单
      tableData: [], //文章列表数据
      loading: false,
      value: '',
      optionsers: [
        {
          label: '待处理',
          value: '0',
        },
        {
          label: '退货中',
          value: '1',
        },
        {
          label: '已完成',
          value: '2',
        },
        {
          label: '已拒绝',
          value: '3',
        },
      ],
    }
  },
  created() {
    this.findReturnApply()
  },
  mounted() {},
  methods: {
    //获取文章列表
    findReturnApply() {
      this.loading = true
      // setTimeout(() => {
      // console.log(orderFor, 'orderFor')
      orderFor
        .findReturnApplyApi(
          this.page.currentPage,
          this.page.pageSize,
          this.from
        )
        .then(res => {
          if (res.success) {
            this.tableData = res.data.rows //获取到线上文字地址
            this.page.total = res.data.total //获取文章总条数
            console.log(this.tableData, 'this.tableData.length')
            this.tableData.forEach(item => {
              item.productAttr = JSON.parse(item.productAttr)
            })
          } else {
            this.$message.error('请求失败')
          }
          console.log(res, 'res')
          this.loading = false
        })
      // })
    },
    //每页多少条 改变时触发事件
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.page.pageSize = val
      this.findReturnApply()
    },
    //修改页触发的事件
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.page.currentPage = val
      this.findReturnApply()
    },
    //查看订单
    resetes(row) {
      console.log(row, '查看订单')
      // orderFor.orderReturnApi(row).then(res => {
      //   console.log(res, 'res')
      // })
      this.$router.push({
        name: 'Chargebackes',
        params: { id: row },
      })
    },
    //查询
    doSearch() {
      this.page = {
        currentPage: 1, //当前页
        pageSizes: [10, 20, 30, 40],
        pageSize: 10, //每页多少条数据
        total: 0, //总数据条数
      }
      this.from = Object.assign({}, this.searchFrom)
      this.findReturnApply()
      console.log(this.searchFrom, 'this.searchFrom')
      console.log(this.from, 'this.from')
    },
    //重置
    reset() {
      this.searchFrom = {}
      this.page = {
        currentPage: 1, //当前页
        pageSizes: [10, 20, 30, 40],
        pageSize: 10, //每页多少条数据
        total: 0, //总数据条数
      }
      this.findReturnApply()
    },
  },
}
</script>

<style lang="scss" scoped>
.main {
  background: #f5f5f5;
  .card {
    width: 96.5%;
    margin: 30px;
  }
}
.condtion {
  background-color: #fff;
  color: #303133;
  font-size: 10px;
}
.users {
  margin-right: 200px;
}
.usered {
  position: relative;
  top: 30px;
}
.el-card__body {
  height: 1200px;
}

.pending {
  background-color: #f56c6c;
  color: #fff;
  width: fit-content;
  border-radius: 3px;
  padding: 3px;
}
.returns {
  background-color: #e6a23c;
  color: #fff;
  width: fit-content;
  border-radius: 3px;
  padding: 3px;
}
.completed {
  background-color: #ecf5ff;
  color: #50a5ff;
  width: fit-content;
  border-radius: 3px;
  padding: 3px;
}
.refuse {
  background-color: #f4f4f5;
  color: #adafb4;
  width: fit-content;
  border-radius: 3px;
  padding: 3px;
}
</style>